package com.mebs.model;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Transient;

import org.hibernate.Session;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

import com.mebs.model.inventory.OrderItem;

/**
 * Created by Sergey Prasolov, sap@jensentechnologies.com
 * Date: Feb 13, 2006, 4:54:26 PM
 */
@Entity()
@DiscriminatorValue("WAREHOUSE")
public class Warehouse extends AbstractVendor{

    @Transient
    public boolean isDeletable(Session session)
    {
        return (Integer)session.createCriteria(OrderItem.class)
            .add(Restrictions.eq("warehouse", this))
            .setProjection(Projections.rowCount())
            .uniqueResult() == 0;
    }

}
